<template>
  <el-dialog
    v-model="dialogVisible"
    :title="null"
    width="400px"
    :show-close="false"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    class="confirmation-dialog"
  >
    <div class="dialog-content">
      <!-- 图标+标题（居左对齐） -->
      <div class="question-section">
        <el-icon :class="iconClass">
          <Warning />
        </el-icon>
        <span class="question-text">{{ props.title }}</span>
      </div>

      <!-- 消息内容（居中对齐） -->
      <div class="warning-section">
        <p class="warning-message">{{ props.message }}</p>
      </div>

      <!-- 取消和确认按钮（居右对齐） -->
      <div class="button-section">
        <el-button @click="handleCancel">{{ props.cancelText }}</el-button>
        <el-button :type="confirmButtonType" @click="handleConfirm">{{ props.confirmText }}</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
import { Warning } from '@element-plus/icons-vue'

// Props
interface Props {
  visible: boolean
  title?: string
  message?: string
  confirmText?: string
  cancelText?: string
  type?: 'warning' | 'danger' | 'info'
}

const props = withDefaults(defineProps<Props>(), {
  visible: false,
  title: '确认操作',
  message: '确定要执行此操作吗？',
  confirmText: '确认',
  cancelText: '取消',
  type: 'warning'
})

// Emits
const emit = defineEmits<{
  'update:visible': [value: boolean]
  'confirm': [result: boolean]
  'cancel': [result: boolean]
}>()

// 响应式数据
const dialogVisible = computed({
  get: () => props.visible,
  set: (value) => emit('update:visible', value)
})

// 计算属性
const iconClass = computed(() => {
  const classMap = {
    warning: 'warning-icon',
    danger: 'danger-icon',
    info: 'info-icon'
  }
  return classMap[props.type] || 'warning-icon'
})

const confirmButtonType = computed(() => {
  const typeMap = {
    warning: 'primary',
    danger: 'danger',
    info: 'primary'
  }
  return typeMap[props.type] || 'primary'
})

// 方法
const handleConfirm = () => {
  emit('confirm', true)
  dialogVisible.value = false
}

const handleCancel = () => {
  emit('cancel', false)
  dialogVisible.value = false
}
</script>

<style scoped>
.confirmation-dialog {
  border-radius: 8px;
}

:deep(.el-dialog) {
  border-radius: 8px;
}

:deep(.el-dialog__header) {
  display: none;
}

:deep(.el-dialog__body) {
  padding: 24px;
}

.dialog-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* 问句区域（居左对齐） */
.question-section {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
}

.warning-icon {
  color: #E6A23C;
  font-size: 20px;
  flex-shrink: 0;
}

.danger-icon {
  color: #F56C6C;
  font-size: 20px;
  flex-shrink: 0;
}

.info-icon {
  color: #409EFF;
  font-size: 20px;
  flex-shrink: 0;
}

.question-text {
  font-size: 16px;
  font-weight: 500;
  color: #303133;
  line-height: 1.4;
}

/* 警告信息区域（居中对齐） */
.warning-section {
  text-align: center;
  padding: 0 16px;
}

.warning-message {
  font-size: 14px;
  color: #606266;
  line-height: 1.6;
  margin: 0;
}

/* 按钮区域（居右对齐） */
.button-section {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.button-section .el-button {
  min-width: 80px;
}
</style>
